<?php
// ==============================================================================================
// Licensed under the GNU GPLv3 (LICENSE.txt)
// ==============================================================================================
// @author     WEBO Software (http://www.webogroup.com/)
// @version    0.1.0
// @copyright  Copyright &copy; 2009-2010 WEBO Software, All Rights Reserved
// ==============================================================================================
// no direct access
defined('_JEXEC') or die('Restricted access');

function com_install() {
    $adminDir = dirname(__FILE__);
	$install_directory = JPATH_SITE . '/components/com_webositeinsight/';
	$url = JURI::root();
	if (substr($url, -1) != '/')
	{
		$url .= '/';
	}
	$url_parts = explode('://', $url, 2);
	$url_parts = explode('/', $url_parts[1], 2);
	$url = $url_parts[1];
	if (substr($url, -1) != '/')
	{
		$url .= '/';
	}
	$adminUrl = $url . 'administrator/index.php?option=com_webositeinsight';
	$backscript = $url . 'components/com_webositeinsight/back-script.php';
	require($install_directory . 'controller/installer.php');

	@copy($adminDir . '/webositeinsight.php', JPATH_SITE . '/plugins/system/webositeinsight.php');
	@copy($adminDir . '/webositeinsight.x', JPATH_SITE . '/plugins/system/webositeinsight.xml');

    if (!@is_file(JPATH_SITE . '/plugins/system/webositeinsight.xml')) {
		return false;
    }
/* publish system plugin */
	$database = & JFactory::getDBO();
/* get order or System - SEF */
	$database->setQuery("SELECT ordering FROM `#__plugins` WHERE element='sef'");
	$database->query();
/* insert WEBO Site InSight right after SEF */
    $database->setQuery(  "INSERT INTO `#__plugins` "
    					. "        (`name`, `element`, `folder`, `access`, `ordering`, `published`, `iscore`, `client_id`, `checked_out`, `checked_out_time`, `params`) "
    					. " VALUES ('System - WEBO Site InSight', 'webositeinsight', 'system', 0, "
						. ($database->loadResult() + 1)
						. ", 1, 0, 0, 0, '0000-00-00 00:00:00', '');");
	$result = $database->query();

	if (!$result) {
    	return false;
	}

}
?>
